package com.gangwangchina.android.contactlib.model;

import java.util.Map;


import android.provider.ContactsContract.Data;

public abstract class DataElement {
	
	/**
	 * The number of data columns in the database
	 */
	public static final int DATA_COLUMNS = 15;
	
	public static final String _ID = Data._ID;
	public static final String MIMETYPE = Data.MIMETYPE;
	public static final String PC_ID = Data.CONTACT_ID;
	
	public long id, personContactId;
	public String mimetype;
	
	/**
	 * 
	 * @param personContactId
	 * @param mimetype
	 */
	public DataElement(long personContactId, String mimetype){
		this.personContactId = personContactId;
		this.mimetype = mimetype;
	}
	
	/**
	 * Sets the PersonContact the DataElement is linked to
	 * @param id
	 */
	public void setNewPersonContactId(long id){
		this.personContactId = id;
	}
	
	/**
	 * Sets a property of the element
	 * @param key the property's key
	 * @param value the property's value
	 * @return true if the operation is successful
	 */
	public boolean setProperty(String key, Object value){
		if(key.equals(MIMETYPE))mimetype = (String) value; 
		else if(key.equals(PC_ID)) personContactId = new Long((Long) value);
		else return false;
		return true;
	}
	
	/**
	 * Accessor to an element's properties
	 * @param key the property(s key
	 * @return true if the operation is successful
	 */
	public Object getProperty(String key){
		if(key.equals(MIMETYPE)) return mimetype; 
		else if(key.equals(PC_ID)) return String.valueOf(personContactId);
		else if(key.equals(_ID)) return String.valueOf(id);
		else return null;
	}
	
	/**
	 * Returns the names of the columns of the table that represents the element in the databse
	 * @return the columns names
	 */
	public abstract Map<String, Object> getDataColumns();
}
